package com.meilingcloud.biobank.controller;

import com.meilingcloud.biobank.domain.SampleTrash;
import com.meilingcloud.biobank.service.ISampleTrashService;
import com.meilingcloud.common.annotation.Log;
import com.meilingcloud.common.core.controller.BaseController;
import com.meilingcloud.common.core.domain.AjaxResult;
import com.meilingcloud.common.core.page.TableDataInfo;
import com.meilingcloud.common.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 样本回收站 Controller
 *
 * @author chenl
 * @date 2021-04-01
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/biobank/sampleTrash")
public class SampleTrashController extends BaseController {

    private final ISampleTrashService iSampleTrashService;

    /**
     * 查询样本回收站 列表
     */
    @PreAuthorize("@ss.hasPermi('biobank:sampleTrash:list')")
    @GetMapping("/list")
    public TableDataInfo list(SampleTrash sampleTrash) {
        startPage();
        List<SampleTrash> list = iSampleTrashService.queryList(sampleTrash);
        return getDataTable(list);
    }

    /**
     * 获取样本回收站 详细信息
     */
    @PreAuthorize("@ss.hasPermi('biobank:sampleTrash:query')")
    @GetMapping(value = "/{sampTrashId}")
    public AjaxResult getInfo(@PathVariable("sampTrashId") Long sampTrashId) {
        return AjaxResult.success(iSampleTrashService.getById(sampTrashId));
    }

    /**
     * 新增样本回收站
     */
    @PreAuthorize("@ss.hasPermi('biobank:sampleTrash:add')")
    @Log(title = "样本回收站 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SampleTrash sampleTrash) {
        return toAjax(iSampleTrashService.save(sampleTrash));
    }

    /**
     * 修改样本回收站
     */
    @PreAuthorize("@ss.hasPermi('biobank:sampleTrash:edit')")
    @Log(title = "样本回收站 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SampleTrash sampleTrash) {
        return toAjax(iSampleTrashService.updateById(sampleTrash));
    }

    /**
     * 删除样本回收站
     */
    @PreAuthorize("@ss.hasPermi('biobank:sampleTrash:remove')")
    @Log(title = "样本回收站 ", businessType = BusinessType.DELETE)
    @DeleteMapping("/{sampTrashIds}")
    public AjaxResult remove(@PathVariable Long[] sampTrashIds) {
        return toAjax(iSampleTrashService.removeByIds(Arrays.asList(sampTrashIds)));
    }

    /**
     * 样本还原
     */
    @PreAuthorize("@ss.hasPermi('biobank:sampleTrash:edit')")
    @Log(title = "样本回收站 ", businessType = BusinessType.UPDATE)
    @PostMapping("/reduce")
    public AjaxResult reduce(@RequestBody List<SampleTrash> sampleTrashs) {
        return toAjax(iSampleTrashService.reduce(sampleTrashs));
    }
}
